package ac.github.os.internal.core.action.plugin

import ac.github.os.internal.core.action.Action
import ac.github.os.internal.core.config.StringConfig
import ac.github.os.internal.core.config.get
import ac.github.os.internal.core.skill.Skill
import ac.github.os.internal.session.Cache
import ac.github.os.internal.session.Session
import taboolib.common.platform.Awake
import taboolib.common.platform.function.submit

@Awake
class AsyncAction : Action {
    override fun onExecute(session: Session, cache: Cache, config: StringConfig) {

        val delay = config.get("delay", 0L)!!
        config.get<List<String>>("list", single = true)?.apply {
            submit(delay = delay, async = true) { forEach { Skill(it).cast(session) } }
        }
    }

    override val type: Action.Type
        get() = Action.Type.AIR
    override val namespace: String
        get() = "async"
}